package com.admin.action.boraction;

import com.admin.Action;
import com.admin.service.borservice.BorServiceImpl;
import com.pojo.BorrowerBean;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

public class BorRechargeAction extends Action {

    /**
     *  前端需要传入用户id以及需要充值的金额
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */

    @Override
    public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        PrintWriter out=response.getWriter();
        HttpSession session = request.getSession();
//        System.out.println(session.getAttribute("adminInfo"));
        if(session.getAttribute("adminInfo")==null){
            out.println("<script>parent.window.location.href='error.html';</script>");
            return;
        }
        BorServiceImpl service = new BorServiceImpl();
        BorrowerBean bor = new BorrowerBean();
        bor.setIdCard(request.getParameter("idCard"));
        System.out.println("身份证号："+request.getParameter("idCard"));
        bor.setBalance(Double.parseDouble(request.getParameter("balance")));
        boolean bool = service.updateBorBalance(bor);
        System.out.println("结果："+bool);
        if (bool) {
            out.print("success");
        } else {
            out.print("error");
        }
    }
}
